import { IContext } from '@/core';
/**
 * 实体服务注册中心
 *
 * @export
 * @class EntityServiceRegister
 */
export class EntityServiceRegister {

	/**
	 * 实体服务注册中心对象
	 *
	 * @private
	 * @static
	 * @type {EntityServiceRegister}
	 * @memberof EntityServiceRegister
	 */
	private static register: EntityServiceRegister;

	/**
	 * Creates an instance of EntityServiceRegister.
	 * 禁止使用new获取实体服务注册中心对象
	 * @memberof EntityServiceRegister
	 */
	private constructor() {}

	/**
	 * 获取实体服务注册中心对象
	 *
	 * @static
	 * @return {*}  {EntityServiceRegister}
	 * @memberof EntityServiceRegister
	 */
	static getInstance(): EntityServiceRegister {
		if (!this.register) {
			this.register = new EntityServiceRegister();
		}
		return this.register;
	}

	/**
	 * 获取实体服务
	 *
	 * @param {string} name 实体名称
	 * @param {IContext} [context={}] 应用上下文
	 * @return {*}  {Promise<any>}
	 * @memberof EntityServiceRegister
	 */
	public async getService(name: string, context: IContext = {}): Promise<any> {
		const targetService: any = await (this as any)[`get${name}Service`](context);
		{{!-- await targetService.loaded(context); --}}
		return targetService;
	}

{{#each app.allPSAppDataEntities as | entity |}}
	/**
	 * {{entity.logicName}}服务
	 *
	 * @param {IContext} [context={}]
	 * @return {*}  {Promise<any>}
	 * @memberof EntityServiceRegister
	 */
	async get{{pascalCase entity.codeName}}Service(context: IContext = {}): Promise<any> {
		return (await import ('@/api/{{spinalCase entity.codeName}}/data-service/{{spinalCase entity.codeName}}-service')).default.getInstance(context);
	}

{{/each}}
}